import unittest
from api.login import LoginAPI
import app



class TestLogin(unittest.TestCase):

    def setUp(self):
        self.login_api = LoginAPI()
    def tearDown(self):
        pass
    def test01_case001(self):
        response =self.login_api.login(
            {
                "mobile":"13800000002",
                "password":"123456"
            }
        )
        print(response.json())

        self.assertEqual(200,response.status_code)
        self.assertEqual(True,response.json().get("success"))
        self.assertEqual(10000, response.json().get("code"))
        self.assertEqual('操作成功！', response.json().get("message"))

    def test01_case100(self):
        response=self.login_api.login(
                {
                    "mobile": "13800000002",
                    "password": "123456"
                }
            )
        print(response.json())

        self.assertEqual(200, response.status_code)
        self.assertEqual(True, response.json().get("success"))
        self.assertEqual(10000, response.json().get("code"))
        self.assertEqual('操作成功！', response.json().get("message"))

        app.TOKEN = "Bearer " +response.json().get("data")
        print(app.TOKEN)
        app.headers_data["Authorization"] = app.TOKEN

    def test01_case002(self):
        response=self.login_api.login(
                {
                    "mobile": "",
                    "password": "123456"
                }
            )
        print(response.json())

        self.assertEqual(200, response.status_code)
        self.assertEqual(False, response.json().get("success"))
        self.assertEqual(20001, response.json().get("code"))
        self.assertEqual('用户名或密码错误', response.json().get("message"))

    def test01_case003(self):
        response=self.login_api.login(
                {
                    "mobile": "13800000002",
                    "password": ""
                }
            )
        print(response.json())

        self.assertEqual(200, response.status_code)
        self.assertEqual(False, response.json().get("success"))
        self.assertEqual(20001, response.json().get("code"))
        self.assertEqual('用户名或密码错误', response.json().get("message"))

    def test01_case004(self):
        response=self.login_api.login(
                {
                    "mobile": "1380000002",
                    "password": "123456"
                }
            )
        print(response.json())

        self.assertEqual(200, response.status_code)
        self.assertEqual(False, response.json().get("success"))
        self.assertEqual(20001, response.json().get("code"))
        self.assertEqual('用户名或密码错误', response.json().get("message"))

    def test01_case005(self):
        response=self.login_api.login(
                {
                    "mobile": "138000000012",
                    "password": "123456"
                }
            )
        print(response.json())

        self.assertEqual(200, response.status_code)
        self.assertEqual(False, response.json().get("success"))
        self.assertEqual(20001, response.json().get("code"))
        self.assertEqual('用户名或密码错误', response.json().get("message"))

    def test01_case006(self):
        response=self.login_api.login(
                {
                    "mobile": "阿萨德群无",
                    "password": "123456"
                }
            )
        print(response.json())

        self.assertEqual(200, response.status_code)
        self.assertEqual(False, response.json().get("success"))
        self.assertEqual(20001, response.json().get("code"))
        self.assertEqual('用户名或密码错误', response.json().get("message"))

    def test01_case007(self):
        response=self.login_api.login(
                {
                    "mobile": "15970255414",
                    "password": "123456"
                }
            )
        print(response.json())

        self.assertEqual(200, response.status_code)
        self.assertEqual(False, response.json().get("success"))
        self.assertEqual(20001, response.json().get("code"))
        self.assertEqual('用户名或密码错误', response.json().get("message"))

    def test01_case008(self):
        response=self.login_api.login(
                {
                    "mobile": "13800000002",
                    "password": "123456",
                    "haha": "xixi"
                }
            )
        print(response.json())

        self.assertEqual(200, response.status_code)
        self.assertEqual(True, response.json().get("success"))
        self.assertEqual(10000, response.json().get("code"))
        self.assertEqual('操作成功！', response.json().get("message"))

    def test01_case009(self):
        response=self.login_api.login(
                {

                    "password": "123456"
                }
            )
        print(response.json())

        self.assertEqual(200, response.status_code)
        self.assertEqual(False, response.json().get("success"))
        self.assertEqual(20001, response.json().get("code"))
        self.assertEqual('用户名或密码错误', response.json().get("message"))

    def test01_case010(self):
        response=self.login_api.login(
                {
                    "mobile": "13800000002"

                }
            )
        print(response.json())

        self.assertEqual(200, response.status_code)
        self.assertEqual(False, response.json().get("success"))
        self.assertEqual(20001, response.json().get("code"))
        self.assertEqual('用户名或密码错误', response.json().get("message"))

    def test01_case011(self):
        response=self.login_api.login(
                {

                }
            )
        print(response.json())

        self.assertEqual(200, response.status_code)
        self.assertEqual(False, response.json().get("success"))
        self.assertEqual(9999, response.json().get("code"))
        self.assertEqual('用户名或密码错误', response.json().get("message"))

    def test01_case012(self):
        response=self.login_api.login(
                {
                    "mobil": "13800000002",
                    "password": "123456"
                }
            )
        print(response.json())

        self.assertEqual(200, response.status_code)
        self.assertEqual(False, response.json().get("success"))
        self.assertEqual(20001, response.json().get("code"))
        self.assertEqual('用户名或密码错误', response.json().get("message"))

    def test01_case013(self):
        response=self.login_api.login(
                    {
                        "mobile": "13800000002",
                        "passwod": "123456"
                    }
                )
        print(response.json())

        self.assertEqual(200, response.status_code)
        self.assertEqual(False, response.json().get("success"))
        self.assertEqual(20001, response.json().get("code"))
        self.assertEqual('用户名或密码错误', response.json().get("message"))
